﻿//alarmwindow.js

/*****************************************************
 * k-phu: 2013/11/22
 * Report/Alarm Report
 *****************************************************/
function alarmWindow() {
	var today = new Date();
	var pagesize = 15;
	var trackNameCombo = new Ext.form.ComboBox({
			name : 'trackname_combox',
			// store: this.combostore,
			mode : 'local',
			displayField : 'trackname',
			width : 200,
			// valueField: this.vfield,
			enableKeyEvents : true,
			fieldLabel : '_ImageButtonText_TrackerName',
			editable : true
		});
	var cbxAlarmType = new Ext.form.ComboBox({
		name : 'cbxAlarmType',
		// store: this.combostore,
		mode : 'local',
		displayField : 'cbxAlarmType',
		width : 80,
		// valueField: this.vfield,
		enableKeyEvents : true,
		fieldLabel : 'cbxAlarmType',
		editable : true
		});
	var fromDateEditor = new Ext.form.DateField({
			renderer : Ext.util.Format.dateRenderer('Y-m-d'),
			format : 'Y-m-d',
			value : today,
			width : 90
		});

	var fromTimeEditor = new Ext.form.TimeField({
			value : '00:00',
			format : 'H:i',
			width : 60
		});

	var toDateEditor = new Ext.form.DateField({
			renderer : Ext.util.Format.dateRenderer('Y-m-d'),
			format : 'Y-m-d',
			value : today,
			width : 90
		});

	var toTimeEditor = new Ext.form.TimeField({
			value : "23:59",
			format : 'H:i',
			width : 60
		});

	var addressCb = new Ext.form.Checkbox({
			checked : false
		});
	var tbar = new Ext.Toolbar({
			items : [
				'_Alarm_TrackerName' + ':',
				trackNameCombo, {
					xtype : 'tbseparator',
					width : 5
				},
				'_Alarm_AlarmType' + ':',
				cbxAlarmType, {
					xtype : 'tbseparator',
					width : 5
				},
				'_Alarm_FromTime' + ':',
				fromDateEditor, {
					xtype : 'tbseparator',
					width : 5
				},
				fromTimeEditor, {
					xtype : 'tbseparator',
					width : 5
				},
				'_Alarm_ToTime' + ':',
				toDateEditor, {
					xtype : 'tbseparator',
					width : 5
				},
				toTimeEditor, {
					xtype : 'tbseparator',
					width : 5
				},
				'_TrackerMain_ARP',
				addressCb, '-', {
					tooltip : {
						text : '_TrackerMain_Search',
						autoHide : true
					},
					icon : 'Content/images/search16.gif',
					handler : function () {
						// alarmstore.load({
						// params: {
						// fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
						// totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value,
						// alarmId: alarmTypeCombo.getValue(),
						// trackName: trackNameCombo.getRawValue(),
						// start: 0,
						// limit: pagesize
						// }
						// });
					}
				}, {
					tooltip : {
						text : '_TrackerMain_ExportToExcel',
						autoHide : true
					},
					icon : 'Content/images/excel16.gif',
					handler : function () {
						// if (!Ext.fly('alarmexcel')) {
						// var frm = document.createElement('form');
						// frm.id = 'alarmexcel';
						// frm.name = id;
						// frm.style.display = 'block';
						// document.body.appendChild(frm);
						// }
						// var requestaddress = false;
						// requestaddress= addressCb.getValue();
						// if (typeof (pcsaddress) != 'undefined') {
						// requestaddress = pcsaddress && addressCb.getValue();
						// }
						// Ext.Ajax.request({
						// url: 'HandlerExcel',
						// form: Ext.fly('alarmexcel'),
						// method: 'POST',
						// params: {
						// exceltype: 'alarm',
						// start: 0,
						// limit: 60000,
						// trackName: trackNameCombo.getRawValue(),
						// alarmId: alarmTypeCombo.getValue(),
						// fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
						// totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value,
						// requestaddress: requestaddress ? "1" : "0"
						// },
						// isUpload: true
						// });
					}
				}, {
					tooltip : {
						text : '_TrackerMain_ExportToKML',
						autoHide : true
					},
					icon : 'Content/images/kml.gif',
					handler : function () {
						// if (!Ext.fly('alarmkml')) {
						// var frm = document.createElement('form');
						// frm.id = 'alarmkml';
						// frm.name = id;
						// frm.style.display = 'none';
						// document.body.appendChild(frm);
						// }
						// Ext.Ajax.request({
						// url: 'HandlerAlarmKML',
						// form: Ext.fly('alarmkml'),
						// method: 'POST',
						// params: {
						// exceltype: 'alarm',
						// start: 0,
						// limit: 60000,
						// trackName: trackNameCombo.getRawValue(),
						// alarmId: alarmTypeCombo.getValue(),
						// fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
						// totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value
						// },
						// isUpload: true
						// });

					}
				}
			]
		});
	var bar = new Ext.PagingToolbar({
			pageSize : pagesize,
			// store: alarmstore,
			displayInfo : true,
			beforePageText : '_Alarm_Page',
			refreshTex : '_Alarm_Refresh',
			displayMsg : '_Alarm_Displaying',
			emptyMsg : '_Alarm_Alarm_emptyMsg'
		});
	var grdAlarm = new Ext.grid.GridPanel({
			//        store: alarmstore,
			loadMask : true,
			//    columns: columns,
			width : 1100,
			height : 450,
			title : '_Alarm_AlarmGrid'
		});
	var alarmWindow = new Ext.Window({
			title : '_Alarm_AlarmWindow',
			layout : 'fit',
			height : 520,
			width : 1230,
			iconCls : 'report-alarm',
			// items: grdAlarm,
			tbar : tbar,
			bbar : bar,
			minimizable : true,
			constrain : true,
			listeners : {
				'minimize' : function () {
					// addTaskButtonForWindow(alarmWindow);
				}
			}
		});
	alarmWindow.show();
};